package com.loukou.lkt.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loukou.lkt.lkt.bo.GoodsBo;
import com.loukou.lkt.lkt.bo.PageList;
import com.loukou.lkt.lkt.enums.PositionTypeEnum;
import com.loukou.lkt.lkt.resp.RespDto;
import com.loukou.lkt.web.processor.SelectGoodsProcessor;

@Controller
@RequestMapping("/selectgoods")
public class SelectGoodsController extends BaseController{
	@Autowired
	private SelectGoodsProcessor selectGoodsProcessor;
	
	@RequestMapping("index")
	public String index(){
		return "selectGoods/index";
	}
	
	@RequestMapping(value="/getGoodsData",method=RequestMethod.GET)
	@ResponseBody
	public RespDto<PageList<GoodsBo>> getGoodsData(
		@RequestParam(value = "sku", required = false, defaultValue = "") String sku,
		@RequestParam(value = "barcode", required = false, defaultValue = "") String barcode,
		@RequestParam(value = "goodsName", required = false, defaultValue = "") String goodsName,
		@RequestParam(value = "warehouseId", required = false, defaultValue = "-1") int warehouseId,
		@RequestParam(value = "pageIndex", required = false, defaultValue = "1") int pageIndex,
		@RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize) {
		if(warehouseId <0){
			return null;
		}
		return selectGoodsProcessor.getSelectGoods(warehouseId, PositionTypeEnum.TYPE_Normal.getId(), sku, barcode, goodsName, pageIndex, pageSize);
	}
	
	@RequestMapping(value="/getOneGoodsData",method=RequestMethod.GET)
	@ResponseBody
	public RespDto<GoodsBo> getOneGoodsData(
		@RequestParam(value = "sku", required = false, defaultValue = "") String sku,
		@RequestParam(value = "warehouseId", required = false, defaultValue = "0") int warehouseId) {
		return selectGoodsProcessor.getOneGoods(warehouseId, PositionTypeEnum.TYPE_Normal.getId(), sku);
	}
}
